<template>
  <el-card shadow="hover">
    <!-- 头部按钮 -->
    <el-form inline>
      <el-form-item>
        <el-input placeholder="用户名" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary">查询</el-button>
        <el-button type="default">清空</el-button>
      </el-form-item>
    </el-form>
    <el-form inline>
      <el-button type="primary">添加</el-button>
      <el-button type="danger">批量删除</el-button>
    </el-form>
    <!-- 表格 -->
    <el-table
      :data="UserList"
      v-loading="loading"
      border
      style="margin-top: 10px"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="序号" type="index" width="180" />
      <el-table-column label="用户名" prop="username" width="180" />
      <el-table-column label="用户昵称" prop="nickName" />
      <el-table-column label="角色列表" prop="roleName" />
      <el-table-column label="创建时间" prop="gmtCreate" />
      <el-table-column label="更新时间" prop="gmtModified" />
      <el-table-column label="操作"></el-table-column>
    </el-table>
  </el-card>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";

export default defineComponent({
  name: "AclUserList",
});
</script>

<script setup lang="ts">
import $Api from "@/api/global-api";
import { ElMessage } from "element-plus";

const page = ref<number>(1); // 当前页
const limit = ref<number>(10); // 总页数
const UserList = ref<any>(); // 用户数据列表
const loading = ref(false);
onMounted(() => {
  getUserList(page.value, limit.value);
});

// 获取用户信息列表
async function getUserList(page: number, limit: number) {
  loading.value = true;
  try {
    const result = await $Api.getUserList(page, limit);
    UserList.value = result.items;
  } catch (error: any) {
    ElMessage.error(error);
  }
  loading.value = false;
}
</script>

<style scoped lang="scss"></style>
